<script>
$(function(){
  $("div.holder").jPages({
    containerID : "itemContainer"
  });

});
</script>
<body>
<div class="main-content" id="main-content">
	<div class="sub-content">
		<div class="top-header products">
			<div class="top_header_title">
				<h1>Product List</h1>
			</div>
			<div class="product_list_details">
			<form id="formid" method="POSt">
				<label>Categories:</label>
					<select id="categories" name="categories" 
					onchange="Categories()">
						<option value="0">Select</option>
						<?php foreach($categories as $key=>$category){ ?>							
							<option value="<?php echo $category->category_id;?>"<?php if(isset($data)){ if($category->category_id==$data){ echo 'selected="selected"';}}?>>
							<?php echo $category->category_name;?></option>
						<?php } ?>
					</select>
					<input type="hidden" id="catogoryValue" name="catogoryValue"value="">
				<a href="/admin/add-product"><input type="button" value="Add product" /></a>
			</form>
			</div>
		</div>
		<? if(count($getallProducts)!=0){?>
		<div class="product_table">		
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr class="bg_header">
					<td width="10%" align="center">S.NO</td>
					<td width="36%" align="left">Product Name</td>
					<td  width="20%" align="center">Quantity</td>
					<td  width="18%" align="center">Price</td>
					<td  width="15%" align="center">Action</td>
				</tr>
			</table>
			<ul id="itemContainer">
			<?php $cnt=1;foreach($getallProducts as $key=>$allproducts){ ?>
			   <li><table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td align="center"><?php echo $cnt; ?></td>
					<td><?php echo $allproducts->genericname; ?></td>
					<td align="center"><?php echo $allproducts->quntity;?></td>
					<td align="center"><?php echo $allproducts->min_price;?></td>
					<td align="center"><a href="/products/add-product?product_id=<? echo $allproducts->product_id;?>"><img src="<?php echo $this->basePath() ?>/images/edit.png" /></a> <a href="javascript:void(0);" onclick="deleteProduct('<? echo $allproducts->product_id;?>')"><img src="<?php echo $this->basePath() ?>/images/delete.png" /></a></td>
				</tr></table>
				</li>
				<?php $cnt++;} ?>
			</ul>			
		</div>
		<div class="page_nav">
			<div class="holder"></div>
		</div>
		<?}else{?>
			<div class="product_table">	
				There is no data.....
			</div>
		<?}?>
	</div>
</div> 
<script>
function Categories(){
	$("#catogoryValue").val($("#categories").val());
	$("#formid").submit();
}
function deleteProduct(product_id){
	$.ajax({
		type:	'POST',
		url:   	'/products/delete-product',
		data:	{product_id:product_id},
		success: function(data){
			if(data.output=='sucusses'){
				window.location=BASE_URL+'/products/products-list';
			}
		}
	});
}
</script>